package service;

import service.impl.recordQueryServiceImpl;
import service.menu.PersonMenuService;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class InTimeSearchService {
    public void recordQuery() throws ParseException, SQLException {
        recordQueryServiceImpl recordQueryService = new recordQueryServiceImpl();
        java.text.SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd");
        System.out.println("1、调房记录查询\n2、缴费记录查询\n3、退宿记录查询\n输入0返回上一层菜单\n请选择：");
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        switch (a) {
            case 1:
                System.out.println("输入时间段");
                String date11 = in.next();
                String date22 = in.next();
                Date date1 =  formatter.parse(date11);
                Date date2 =  formatter.parse(date22);
                int code1 = recordQueryService.regexChangeRecordInfo(date1,date2);
                if(code1 == 200){
                    System.out.println( recordQueryService.regexChangeRecord(date1,date2));
                }
                else if(code1 == 4){
                    System.out.println("无调换记录");
                }else{
                    System.out.println("错误");
                }
                System.out.println("输入0返回上一层菜单");
                int  a1 = in.nextInt();
                if ( 0 == a1){
                    recordQuery();
                }
                break;
            case 2:
                System.out.println("输入时间段");
                String date33 = in.next();
                String date44 = in.next();
                Date date3 =  formatter.parse(date33);
                Date date4 =  formatter.parse(date44);
                int code2 = recordQueryService.regexPayRecordInfo(date3,date4);
                if(code2 == 200){
                    System.out.println( recordQueryService.regexPayRecord(date3,date4));
                }
                else if(code2 == 5){
                    System.out.println("无缴费记录");
                }else{
                    System.out.println("错误");
                }
                System.out.println("输入0返回上一层菜单");
                int  a2 = in.nextInt();
                if ( 0 == a2){
                    recordQuery();
                }
                break;
            case 3:
                System.out.println("输入时间段");
                String date55 = in.next();
                String date66 = in.next();
                Date date5 =  formatter.parse(date55);
                Date date6 =  formatter.parse(date66);
                int code3 = recordQueryService.regexAwayRecordInfo(date5,date6);
                if(code3 == 200){
                    System.out.println( recordQueryService.regexAwayRecord(date5,date6));
                }
                else if(code3 == 6){
                    System.out.println("无离宿记录");
                }else{
                    System.out.println("错误");
                }
                System.out.println("输入0返回上一层菜单");
                int  a3 = in.nextInt();
                if ( 0 == a3){
                    recordQuery();
                }
                break;
            default:
                PersonMenuService pms = new PersonMenuService();
                pms.messageSys();
        }

    }


}
